package org.diffshop.product.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.diffshop.common.utils.PageUtils;
import org.diffshop.common.utils.Query;

import org.diffshop.product.dao.PmsSpuImagesDao;
import org.diffshop.product.entity.PmsSpuImagesEntity;
import org.diffshop.product.service.PmsSpuImagesService;


@Service("pmsSpuImagesService")
public class PmsSpuImagesServiceImpl extends ServiceImpl<PmsSpuImagesDao, PmsSpuImagesEntity> implements PmsSpuImagesService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PmsSpuImagesEntity> page = this.page(
                new Query<PmsSpuImagesEntity>().getPage(params),
                new QueryWrapper<PmsSpuImagesEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 保存spuImage
     * @param spuId
     * @param images
     */
    @Override
    public void saveSpuImageInfo(Long spuId, List<String> images) {
        if (images != null && images.size() > 0){
            List<PmsSpuImagesEntity> entityList = images.stream().map(image -> {
                PmsSpuImagesEntity entity = new PmsSpuImagesEntity();
                entity.setSpuId(spuId);
                entity.setImgUrl(image);
                return entity;
            }).collect(Collectors.toList());
            this.saveBatch(entityList);
        }
    }

}
